package com.e.SQL;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class UserDBHepler extends SQLiteOpenHelper {

    //1.设置数据库和表名常量
    private static final String DATABASE_NAME = "myDB";     //数据库的名字
    private static final int DATABASE_VERSION = 2;         //数据库版本
    private static final String TABLE_NAME = "user";       //创建用户表
    private static final String TABLE_NAME_1 ="ticket";    //创建预约表


    public UserDBHepler(Context context){
        super(context,DATABASE_NAME,null,DATABASE_VERSION);

    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        //创建用户表
        String strSQL = "create table " + TABLE_NAME
                +"(sno varchar(12) primary key,"
                +"sname varchar(10),phone varchar(11),"
                +"college varchar(10),sdept varchar(10),ssex varchar(2),password varchar(16))";
        String strSQL1 = "create table "+ TABLE_NAME_1
                + "(id integer primary key autoincrement,"
                + "sno varchar(12),sname varchar(10),date1 varchar(15),"
                + "start varchar(10),last varchar(10),"
                + "phone varchar(11))";
        db.execSQL(strSQL1);
        db.execSQL(strSQL);
        String str = "insert into user values('201938170134','李川东','18481823357','信息工程学院','2019计算机科学与技术05','男','123')";
        db.execSQL(str);
        str = "insert into user values('201938170135','李川东1','18481823357','信息工程学院','2019计算机科学与技术05','男','123456789')";
        db.execSQL(str);
        str = "insert into user values('201938170136','李川东2','18481823358','信息工程学院','2019计算机科学与技术05','男','123456789')";
        db.execSQL(str);
        str = "insert into user values('201938170137','李川东3','18481823359','信息工程学院','2019计算机科学与技术05','男','1234444')";
        db.execSQL(str);
        str = "insert into user values('201938170138','李川东4','18481823310','信息工程学院','2019计算机科学与技术05','男','wqeqwe')";
        db.execSQL(str);
        str = "insert into user values('201938170139','李川东5','18481823311','信息工程学院','2019计算机科学与技术05','男','wqeqwweqw'),('1','李川东5','18481823311','信息工程学院','2019计算机科学与技术05','男','1')";
        db.execSQL(str);


    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int i, int i1) {

        if (i==2){
            String s1 = "drop table "+TABLE_NAME;
            String s2 = "drop table "+TABLE_NAME_1;
            db.execSQL(s1);
            db.execSQL(s2);
        }
        String strSQL = "create table " + TABLE_NAME
                +"(sno varchar(12) primary key,"
                +"sname varchar(10),phone varchar(11),"
                +"college varchar(10),sdept varchar(10),ssex varchar(2),password varchar(16))";
        String strSQL1 = "create table "+ TABLE_NAME_1
                + "(id integer primary key autoincrement,"
                + "sno varchar(12),sname varchar(10),date1 varchar(15),"
                + "start varchar(10),last varchar(10),"
                + "phone varchar(11))";
        db.execSQL(strSQL1);
        db.execSQL(strSQL);
        String str = "insert into user values('201938170134','李川东','18481823357','信息工程学院','2019计算机科学与技术05','男','123456789')";
        db.execSQL(str);
        str = "insert into user values('201938170135','李川东1','18481823357','信息工程学院','2019计算机科学与技术05','男','123456789')";
        db.execSQL(str);
        str = "insert into user values('201938170136','李川东2','18481823358','信息工程学院','2019计算机科学与技术05','男','123456789')";
        db.execSQL(str);
        str = "insert into user values('201938170137','李川东3','18481823359','信息工程学院','2019计算机科学与技术05','男','1234444')";
        db.execSQL(str);
        str = "insert into user values('201938170138','李川东4','18481823310','信息工程学院','2019计算机科学与技术05','男','wqeqwe')";
        db.execSQL(str);
        str = "insert into user values('201938170139','李川东5','18481823311','信息工程学院','2019计算机科学与技术05','男','wqeqwweqw')";
        db.execSQL(str);

    }
}
